﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.EF;
using PNProject.Core;

namespace PNProject.Core.Converter
{
    public class NewsConverter
    {
        public static News ToNews(NewsModel news)
        {
            News obj = new News(); 
            try
            {
                obj.NewsID = news.NewsID;
                obj.Title = news.Title;
                obj.TLink = news.TLink;
                obj.TitleEN = news.TitleEN;
                obj.TLinkEN = news.TLinkEN;
                obj.Short = news.Short;
                obj.Lang = news.Lang;
                obj.ShortEN = news.ShortEN;
                obj.ContentVN = news.ContentVN;
                obj.ContentEN = news.ContentEN;
                obj.Avatar = news.Avatar;
                obj.CType = news.CType;
                obj.CreateBy = news.CreateBy;
                obj.UpdateBy = news.UpdateBy;
                obj.ViewCount = news.ViewCount;
                obj.CommentAllow = news.CommentAllow;
                obj.IsChecked = news.IsChecked;
                obj.AttachFiles = news.AttachFiles;
                return obj;
            }
            catch (Exception e)
            {
                return new News();
            }
        }

        public static News CopyNews(News news)
        {
            News obj = new News();
            try
            {
                obj.NewsID = news.NewsID;
                obj.Title = news.Title;
                obj.TLink = news.TLink;
                obj.TitleEN = news.TitleEN;
                obj.TLinkEN = news.TLinkEN;
                obj.Short = news.Short;
                obj.ShortEN = news.ShortEN;
                obj.ContentVN = news.ContentVN;
                obj.ContentEN = news.ContentEN;
                obj.Avatar = news.Avatar;
                obj.CType = news.CType;
                obj.CreateBy = news.CreateBy;
                obj.UpdateBy = news.UpdateBy;
                obj.ViewCount = news.ViewCount;
                obj.LastUpdate = news.LastUpdate;
                obj.CreateDate = news.CreateDate;
                obj.CommentAllow = news.CommentAllow;
                obj.IsChecked = news.IsChecked;
                obj.AttachFiles = news.AttachFiles;
                return obj;
            }
            catch (Exception e)
            {
                return null;
            }
        }

        public static NewsModel NewsTo(News news)
        {
            NewsModel obj = new NewsModel();
            obj.NewsID = news.NewsID;
            obj.Title = news.Title;
            obj.TLink = news.TLink;
            obj.TitleEN = news.TitleEN;
            obj.TLinkEN = news.TLinkEN;
            obj.Short = news.Short;
            obj.ShortEN = news.ShortEN;
            obj.ContentVN = news.ContentVN;
            obj.ContentEN = news.ContentEN;
            obj.Avatar = news.Avatar;
            obj.CType = news.CType.HasValue ? news.CType.Value : 1;
            obj.CreateBy = news.CreateBy;
            obj.UpdateBy = news.UpdateBy;
            obj.ViewCount = news.ViewCount.HasValue ? news.ViewCount.Value : 0;
            obj.AttachFiles = news.AttachFiles;
            obj.LastUpdate = news.LastUpdate.HasValue ? news.LastUpdate.Value.ToString() : "";
            obj.CreateDate = news.CreateDate.HasValue ? news.CreateDate.Value.ToString() : "";
            obj.CommentAllow = news.CommentAllow.HasValue ? news.CommentAllow.Value : false;
            obj.IsChecked = news.IsChecked.HasValue ? news.IsChecked.Value : false;
            obj.Lang = news.Lang.HasValue ? news.Lang.Value : true;
            return obj;
        }
    }
}